dbeaver/pro#7562 [CB] keep data editor filter state during session - #4261
Conversation
allow using attrName without attrPosition
replaced private restorePendingState() with public restoreViewState(pinnedColumnNames, columnOrderNames?) that takes data directly as arguments
bug with skipping constraints if any without a position.
if (!prevColumn) {
return;
}
… in GridViewAction
…of github.com:dbeaver/cloudbeaver into 7562-cb-keep-data-editor-filter-state-after-reconnect
… centralized state persistence
…LDataFilter" This reverts commit 3e0e86f. Last test showed that we don't need any additional logic on BE. It handles all constraints properly.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes. Give us feedback
…DatabasePersistedStateStore and update related references
…f github.com:dbeaver/cloudbeaver into 7562-cb-keep-data-editor-filter-state-during-session
| private applyPersistedConstraints(): void { | ||
| const options = this.source.options; | ||
|
|
||
| if (!options || !validatePersistedState(this.store)) { | ||
| return; | ||
| } | ||
|
|
||
| if ('constraints' in options && 'whereFilter' in options) { | ||
| options.constraints = this.store.constraints.map(c => ({ | ||
| attributeName: c.attributeName, | ||
| operator: c.operator, | ||
| value: c.value, | ||
| orderAsc: c.orderAsc, | ||
| orderPosition: c.orderPosition, | ||
| })); | ||
| options.whereFilter = this.store.whereFilter || ''; | ||
| } | ||
| } |
There was a problem hiding this comment.
please move to result set data source
| for (const name of pinnedColumnNames) { | ||
| const key = this.columnKeys.find(k => this.getColumnName(k) === name); | ||
|
|
||
| if (key) { | ||
| this.pinnedColumns.add(GridDataKeysUtils.serialize(key)); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
i will suggest to move validation logic for pinned columns and columns order to the updateResult method
| ps.set(COLUMN_ORDER_KEY, isCustomOrder ? columnNames : []); | ||
| } | ||
|
|
||
| restoreViewState(state: IRestoreViewState): void { |
There was a problem hiding this comment.
try to use direct states from store instead of syncing private properties with state
| return this.result.data?.columns?.find(c => c.position === colIdx)?.name; | ||
| } | ||
|
|
||
| private persistConstraints(): void { |
There was a problem hiding this comment.
we need to persist datasource options object (whereFilter) maybe it will be better to persist constraints in the same place instead of splitting it across classes
- DatabasePersistedStateStore: pure KV (observable.ref + actions) - DatabaseDataSource: add loadPersistedState() + onPersistedStateLoaded() hook - DatabaseDataConstraintAction: own the constraint persist - ResultSetDataSource: thin dispatcher - GridViewAction: columnsOrder/pinnedColumns become computed getters
…ards, simplify persisted data filter state handling
…g and layout resolution
…op constraint persistence hacks
…ss implementation
| executionContext: observable, | ||
| }); | ||
|
|
||
| this.persistConstraintsDisposer = autorun(() => persistDataFilterConstraints(this)); |
There was a problem hiding this comment.
i will recommend to initialize it after applyPersistedDataFilterConstraints(this); to avoid collisions
but honestly this is bad that we use DatabaseDataConstraintAction in the DataSource (it was so before you changes, but now there is more dependencies on it)
There was a problem hiding this comment.
The separate ticket will be created for this and bellow comments
| const options = source.options; | ||
| if (!options) { | ||
| return; | ||
| } | ||
|
|
||
| const constraints = source.persistedState.get<SqlDataFilterConstraint[]>(CONSTRAINTS_KEY); | ||
| const whereFilter = source.persistedState.get<string>(WHERE_FILTER_KEY); | ||
|
|
||
| if (!Array.isArray(constraints) || typeof whereFilter !== 'string') { | ||
| return; | ||
| } | ||
|
|
||
| runInAction(() => { | ||
| options.constraints = constraints.map(constraint => ({ ...constraint })); | ||
| options.whereFilter = whereFilter; | ||
| }); |
There was a problem hiding this comment.
how about:
| const options = source.options; | |
| if (!options) { | |
| return; | |
| } | |
| const constraints = source.persistedState.get<SqlDataFilterConstraint[]>(CONSTRAINTS_KEY); | |
| const whereFilter = source.persistedState.get<string>(WHERE_FILTER_KEY); | |
| if (!Array.isArray(constraints) || typeof whereFilter !== 'string') { | |
| return; | |
| } | |
| runInAction(() => { | |
| options.constraints = constraints.map(constraint => ({ ...constraint })); | |
| options.whereFilter = whereFilter; | |
| }); | |
| const constraints = source.persistedState.get<SqlDataFilterConstraint[]>(CONSTRAINTS_KEY); | |
| const whereFilter = source.persistedState.get<string>(WHERE_FILTER_KEY); | |
| if (!Array.isArray(constraints) || typeof whereFilter !== 'string') { | |
| return; | |
| } | |
| source.setOptions({ | |
| ...source.options, | |
| constraints: constraints.map(constraint => ({ ...constraint })), | |
| whereFilter | |
| }); |
| source.options!.constraints = []; | ||
| source.options!.whereFilter = ''; |
There was a problem hiding this comment.
i will recommend to use .setOptions
| loadPersistedState(state: Record<string, unknown>): this { | ||
| this.persistedState.setStore(state); |
There was a problem hiding this comment.
setStore but state: Record<string, unknown>
…https://github.com/dbeaver/cloudbeaver into 7562-cb-keep-data-editor-filter-state-during-session
No description provided.